﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using ThatsMeSDK.Core;
using ThatsMeSDK;

namespace TMSamplePhoneApp
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Konstruktor
        public MainPage()
        {
            InitializeComponent();
            WriteLine("initialation completed!");
        }

        private void btnMultiasynctest_Click(object sender, RoutedEventArgs e)
        {
            ServiceHandler.GetMemberByIdCompleted += new GetMemberCompleted(ServiceHandler_GetMemberByIdCompleted);
            ServiceHandler.GetNewPicsCompleted += new LoadPicturesCompleted(ServiceHandler_GetNewPicsCompleted);

            ServiceHandler.GetNewPics(5);
            ServiceHandler.GetMemberById(179);
        }

        void ServiceHandler_GetNewPicsCompleted(object sender, LoadPicturesCompletedEventArgs e)
        {
            WriteLine("new pics have been loaded!");

            foreach (GalleryPicture pic in e.Pictures)
            {
                WriteLine("Image: " + pic.Id.ToString());
            }
        }

        void ServiceHandler_GetMemberByIdCompleted(object sender, GetMemberCompletedEventArgs e)
        {
            WriteLine("member has been loaded!");
            WriteLine("Member: " + e.Member.Nick);
        }

        void WriteLine(string message)
        {
            this.lbOutpu.Items.Insert(0, DateTime.Now.ToString() + " > " + message);
        }
    }
}